/**
 * Leetcode - q897
 */
package com.felix.algorithms.q897;

import com.felix.algorithms.tree.TreeNode;

class Solution1 implements Solution {

    private TreeNode increasingBST(TreeNode root) {
        TreeNode newNode = new TreeNode(0);
        TreeNode pre = newNode;
        helper(root, pre);
        return newNode.right;
    }

    private TreeNode helper(TreeNode root, TreeNode pre) {
        if (root == null) return pre;
        TreeNode curPre = helper(root.left, pre);
        curPre.right = root;
        root.left = null;
        return helper(root.right, root);
    }

}
